package com.dai.demos;

import com.alibaba.fastjson.JSON;
import com.dai.demos.ComponentBean;
import com.dai.demos.ConfigBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
public class BeanController {

    /**
     * 1、经典的注解引入方式 就是在@Configuration注解下生存bean
     */
    @Autowired
    private ConfigBean configBean;

    /**
     * 2、通过@Component方式注入bean 这里通过构造方法引入方式（也可和同上通过@Autowired注入）
     */
    @Autowired
    private ComponentBean componentBean;


    @GetMapping(path="/bean")
    public String show(String name){
        Map<String,String> map = new HashMap<>();
        map.put("ComponentBean",componentBean.getName(name));
        map.put("ConfigBean",configBean.getName(name));
        return JSON.toJSONString(map);
    }
}
